<?php
namespace app\serverauth\validate;
use \app\manage\validate\BaseValidate;
/**
 * 角色管理的验证类
 * @author adv30 <adv30@126.com>
 */
class Role extends BaseValidate
{
    // 是否使用true基础的验证规则
    // protected $useBaseRules = false;
    protected $rule = [
        'id' => ['integer', 'gt' => '0'],
        'name' => ['alphaNum', 'length' => '2,20'],
        'name_cn' => ['chs', 'length' => '2,20'],
        'weight' => ['integer', 'between' => '0,100'],
        'menu' => ['min' => '2'],
        'roles' => ['min' => '2'],
        'app_id' => ['integer', 'gt' => '0'],
        'user_id' => ['integer', 'gt' => '0'],
        'role_id' => ['integer', 'gt' => '0'],
        'apply_info' => ['regex' => '^{.*}$'],
    ];
    protected $message = [
        'name.length' => '名称的长度应在2-20个字符',
        'weight' => '权重只能为0-100整数',
    ];
    protected $scene = [
        'add' => ['name', 'weight'],
        'stop' => ['id', 'name'],
        'start' => ['id', 'name'],
        'list' => ['page', 'list_rows'],
        'edit' => ['id', 'name', 'name_cn', 'weight', 'menu'],
        'getIdsByRoles' => ['roles'],
        'apply' => ['app_id','user_id', 'role_id', 'apply_info'],
        'allowApply' => ['app_id', 'user_id'],
        'giveRoles' => ['id', 'name', 'phone', 'role_id'],
        'allRolesByApp' => ['id', 'name', 'app_key'],
        'removeUserRole' => ['id', 'name', 'phone', 'role_id'],
    ];
}
